//  Created by <Omar MALAGOUEN>

//  Copyright 2011 All rights reserved.
//

#include "cripdvd.h"
#include "ui_cripdvd.h"

CRipDVD::CRipDVD(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::CRipDVD)
{
    ui->setupUi(this);
    settings = new QSettings(QSettings::NativeFormat,QSettings::UserScope,
                             QCoreApplication::organizationName(),
                             QCoreApplication::applicationName());

    ui->pushButtonScan->setDisabled(true);
    ui->startDVDButton->setDisabled(true);
    ui->progressBarScanningDVD->setValue(0);




    alreadyDone = 0;
    processGetInfo = new QProcess;

    numberOfTitleInDVD = 0;
#if defined(Q_OS_MACX)
    ui->lineEditDVDPath->setText("/Volumes/Gad Elmaleh Spectacle");
    ui->lineEditDVDWorkingDirectory->setText("/Volumes/iMovie/build-dvd/GAD DVD1");
#elif defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
    ui->lineEditDVDPath->setText("D:/DVD-MPlayer/Led Zeppelin DVD2.iso");
    ui->lineEditDVDWorkingDirectory->setText("D:/DVD-MPlayer/");
#else
#endif

    ui->lineEditDVDPath->setText(settings->value("lastDVDDirectory").toString());
    ui->lineEditDVDWorkingDirectory->setText(settings->value("lastWorkingDirectory").toString());


    connect(processGetInfo,SIGNAL( readyReadStandardOutput () ),this,SLOT(readDVDInfo() ) );
    //connect(processGetInfo,SIGNAL( readyReadStandardError () ),this,SLOT(readDVDInfo() ) );
    connect(processGetInfo,SIGNAL( finished(int,QProcess::ExitStatus) ),this,
            SLOT(finishedScanning(int,QProcess::ExitStatus) ) );



    QTreeWidget *treeWidget = ui->treeWidget;
    treeWidget->setHeaderLabels(QStringList() << "Track" << "Type" << "Description");
    connect(treeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int) ),this,SLOT(treeWidgetClicked(QTreeWidgetItem *, int) ) );
    connect(treeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int) ),this,SLOT(treeWidgetClicked(QTreeWidgetItem *, int) ) );


    ui->treeWidget->header()->setStretchLastSection(false);
    ui->treeWidget->header()->setResizeMode(0,QHeaderView::ResizeToContents);
    ui->treeWidget->header()->setResizeMode(1,QHeaderView::ResizeToContents);
    ui->treeWidget->header()->setResizeMode(2,QHeaderView::ResizeToContents);

}

CRipDVD::~CRipDVD()
{
    delete ui;
}

void CRipDVD::changeCheckState(QTreeWidgetItem *root,int column)
{
    if( root && root->childCount())
    {
        int childCount = root->childCount();
        for( int i = 0; i != childCount; i++ )
        {
            root->child(i)->setExpanded(root->child(i)->isExpanded());
            root->child(i)->setCheckState(column,root->checkState(column));
        }
    }
}

void CRipDVD::treeWidgetClicked(QTreeWidgetItem *item, int column)
{
    changeCheckState(item,column);
}

void CRipDVD::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void CRipDVD::on_cancelDVDButton_clicked()
{
    this->close();
}

void CRipDVD::on_lineEditDVDPath_textChanged(QString str)
{
    QDir dir(str);
    QFile file(str);
    if ( ( dir.exists() || file.exists() ) && ui->lineEditDVDWorkingDirectory->text() != "")
        ui->pushButtonScan->setEnabled(true);
    else
        ui->pushButtonScan->setEnabled(false);
}

void CRipDVD::on_lineEditDVDWorkingDirectory_textChanged(QString str)
{
    QFile iso(ui->lineEditDVDPath->text());
    if ( str != "" &&  iso.exists() )
        ui->pushButtonScan->setEnabled(true);
    else
        ui->pushButtonScan->setEnabled(false);
}

void CRipDVD::on_openDVDButton_clicked()
{

    QString fileName = QFileDialog::getExistingDirectory(this,tr("Choose a directory"),
                                                         settings->value("lastDVDDirectory").toString());
    if (fileName != "")
    {
        ui->lineEditDVDPath->setText(fileName);
    }
}

void CRipDVD::on_openISOButton_clicked()
{
    QString filterExtension("All supported file (*.iso *.nrg *.cue *.img);;All files (*.*);;") ;
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                    settings->value("lastDVDDirectory").toString(),
                                                    tr(filterExtension.toLatin1().data()));
    if (fileName != "")
    {
        ui->lineEditDVDPath->setText(fileName);
    }
}

void CRipDVD::on_dvdWorkingDirectoryButton_clicked()
{
    QString fileName = QFileDialog::getExistingDirectory(this,tr("Choose a directory"),
                                                         settings->value("lastWorkingDirectory").toString());
    if (fileName != "")
    {
        ui->lineEditDVDWorkingDirectory->setText(fileName);
    }
}

void CRipDVD::on_pushButtonScan_clicked()
{

    ui->pushButtonScan->setDisabled(true);
    ui->label_StateScanDVD->setText(tr("DVD Scan in progress ..."));

    settings->setValue("lastWorkingDirectory", ui->lineEditDVDWorkingDirectory->text());
    settings->setValue("lastDVDDirectory", ui->lineEditDVDPath->text());
    settings->sync();

    this->alreadyDone = 0;
    this->numberOfTitleInDVD = 0;
    for(int j = 0; j < 1024;j++)
        allInfoDVD[j] = "";


    DVDWorkingDirectory = ui->lineEditDVDWorkingDirectory->text();
    QDir DirDVDWorkingDirectory;
    DVDPath = ui->lineEditDVDPath->text();

    ui->treeWidget->clear();
    this->list_title.clear();
    this->list_info_file.clear();

    if ( ! DirDVDWorkingDirectory.exists(DVDWorkingDirectory) )
    {
        qDebug("Trying to create directory %s",DVDWorkingDirectory.toLatin1().data());
        if ( ! DirDVDWorkingDirectory.mkpath(DVDWorkingDirectory))
        {
            QString errorMsg = tr("Enable to create directory ") + DVDWorkingDirectory;
            qDebug("%s",errorMsg.toLatin1().data());
            QMessageBox::information( 0, "Kakola :-)",errorMsg);
            return ;
        }
    }

    DVDWorkingDirectory = QDir::cleanPath(DVDWorkingDirectory);
    DVDPath = QDir::cleanPath(DVDPath);

    scanDVDTitle();
    ui->pushButtonScan->setDisabled(false);
}

void CRipDVD::scanDVDTitle()
{
    this->alreadyDone++;
    delete  processGetInfo;

    processGetInfo = new QProcess;
    connect(processGetInfo,SIGNAL( readyReadStandardOutput () ),this,SLOT(readDVDInfo() ) );
    connect(processGetInfo,SIGNAL( finished(int,QProcess::ExitStatus) ),this,
            SLOT(finishedScanning(int,QProcess::ExitStatus) ) );

    qDebug("Ready to scan DVD %s to %s", DVDPath.toLatin1().data()
           , DVDWorkingDirectory.toLatin1().data());
    QString cmdGetInfo;
    QStringList arguments;

    QString title = QString("dvd://") + QString::number(this->alreadyDone,10);
    arguments << "-identify"
            //<< "-v"
            <<  "-vo" << "null" <<  "-ao" << "null" << title << "-dvd-device"
            << DVDPath
            ;
    QString program = settings->value("mplayer","mplayer").toString();
    cmdGetInfo = program + " " + arguments.join(" ");
    qDebug("Scanning DVD %s",cmdGetInfo.toLatin1().data());
    chrono.restart();
    processGetInfo->start(program,arguments);

    if ( processGetInfo->waitForStarted() == false )
    {
        QString errorMsg =
                QString("Enable to start process %1, be sure this program is installed").arg(program);
        qDebug("%s", errorMsg.toLatin1().data());
        QMessageBox::information( 0, "Kakola :-)",errorMsg); 
      
    }
}

void CRipDVD::setInfoTitle(int t_number)
{
    //allInfoDVD[t_number].replace(QRegExp("Starting playback.*"),"END OF SCAN");

    QString strTitleNumber ;
    QRegExp reg("ID_DVD_CURRENT_TITLE=([0-9]+)");
    if ( allInfoDVD[t_number].contains(reg) )
        strTitleNumber = reg.cap(1);
    bool rb = false;
    QString dir = this->DVDWorkingDirectory + "/" + strTitleNumber;
    dir = QDir::cleanPath(dir);
    QDir qdir(dir);
    qdir.mkpath(dir);
    QString strFile = dir + QString("/dvd-") + strTitleNumber + QString(".log");
    QFile *fichier = new QFile( strFile );
    qDebug("Openning file %s",strFile.toLatin1().data());
    fichier->open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream flux(fichier);
    flux << allInfoDVD[t_number];
    fichier->close();

    reg = QRegExp("There are ([0-9]+) titles on this DVD");
    if ( this->allInfoDVD[t_number].contains(reg) && this->numberOfTitleInDVD == 0 )
    {
        this->numberOfTitleInDVD = reg.cap(1).toInt(&rb,10);
        qDebug("The DVD contains %d titles", this->numberOfTitleInDVD);
        ui->progressBarScanningDVD->setMaximum(this->numberOfTitleInDVD);
        ui->label_StateScanDVD->setText(tr("DVD Scan in progress ..."));
        ui->pushButtonScan->setDisabled(true);
    }

    ui->progressBarScanningDVD->setValue(t_number);

    CSleeper::msleep(100);
}

void CRipDVD::readDVDInfo()
{
    char strBuffer[2048];

    while( processGetInfo->readLine(strBuffer,sizeof(strBuffer))> 0 )
    {
        allInfoDVD[this->alreadyDone] =  allInfoDVD[this->alreadyDone] + QString(strBuffer);
        QString stringBuffer(strBuffer);

        //qDebug("Cleaning buffer for title %d",this->alreadyDone);
        //int i = 0;
        //for(i = 0; i != 2047; i++)
        //    strBuffer[i] = '\0';
        //CSleeper::msleep(10);

        int timeout = 30000; //millisecond
        if (    chrono.elapsed()  > timeout
                || stringBuffer.contains("*** [vo]")
            || stringBuffer.contains("ID_EXIT=EOF")
            || stringBuffer.contains("Starting playback")
            )
            {
            if (chrono.elapsed()  > timeout)
            {
                qDebug("Timeout for reading DVD title %d",this->alreadyDone);
            }
            else if (stringBuffer.contains("ID_EXIT=EOF"))
                qDebug("ID_EXIT=EOF reading DVD title %d",this->alreadyDone);

            qDebug("Killing process processGetInfo for title %d",this->alreadyDone);
            processGetInfo->kill();
        }
    }
}

void CRipDVD::finishedScanning(int exitCode,QProcess::ExitStatus exitStatus){
    qDebug("Signal finished process for title %d / %d", this->alreadyDone, this->numberOfTitleInDVD);
    this->setInfoTitle(this->alreadyDone);
    if (this->alreadyDone < this->numberOfTitleInDVD)
        this->scanDVDTitle();
    else
    {
        ui->label_StateScanDVD->setText(tr("DVD Scan done, Select your title and click Start to continue"));
        ui->pushButtonScan->setEnabled(true);
        ui->startDVDButton->setEnabled(true);
        if (this->numberOfTitleInDVD == 0)
        {
            ui->label_StateScanDVD->setText(tr("NO TRACK ON YOUR DVD, insert a Video DVD !!!"));
            int i = 0;

            QTreeWidgetItem *item_vob = new QTreeWidgetItem(ui->treeWidget);
            item_vob->setText(i,tr("No track on this DVD"));
            item_vob->setText(i+1,tr("ERROR"));
            item_vob->setText(i+2,tr("Please insert a video DVD or a ISO video DVD"));
            ui->progressBarScanningDVD->setValue(ui->progressBarScanningDVD->maximum());
        }
        this->alreadyDone = 0;
        this->fill_list_title();
    }
}

c_subtitle::c_subtitle(QString DVDWorkingDirectory, int title_number, int sid, QString infoVideoDVD)
{
    this->DVDWorkingDirectory = DVDWorkingDirectory;
    this->title_number = title_number;
    this->sid = sid;
    //qDebug("ID_SUBTITLE_ID=%d",this->sid);
    this->lang = regexBetween(infoVideoDVD,"ID_SID_" + QString::number(this->sid) + "_LANG=(\\S+)");
    idx_file_name = DVDWorkingDirectory + QString("/%1/video-title-%2-sid-%3-lang-%4.idx")
                    .arg(title_number).arg(title_number).arg(sid).arg(this->lang);
    sub_file_name = DVDWorkingDirectory + QString("/%1/video-title-%2-sid-%3-lang-%4.sub")
                    .arg(title_number).arg(title_number).arg(sid).arg(this->lang);
    //qDebug("idx_file_name=%s",idx_file_name.toLatin1().data());
    //qDebug("sub_file_name=%s",sub_file_name.toLatin1().data());
}

c_audio::c_audio(){

}


c_title::c_title(QString DVDWorkingDirectory, int title_number,QString infoVideoDVD)
{
    this->DVDWorkingDirectory =  DVDWorkingDirectory;
    this->title_number = title_number;
    this->chapter_filename = DVDWorkingDirectory + QString("/%1/chapters-title-%1.log")
                             .arg(title_number);// DVDWorkingDirectory/5/chapters-title-5.log
    this->profile = DVDWorkingDirectory + QString("/%1/video-title-%1.profile")
                    .arg(title_number);// DVDWorkingDirectory/5/video-title-5.profile
    this->vob_file = DVDWorkingDirectory + QString("/%1/video-title-%1.vob")
                     .arg(title_number);// DVDWorkingDirectory/5/video-title-5.vob
    this->info_file_of_title = DVDWorkingDirectory + QString("/%1/dvd-%1.log")
                               .arg(title_number);// DVDWorkingDirectory/5/dvd-5.vob

    //qDebug("______________________ Title %d ______________________________",title_number);

    bool *b = new bool;
    this->id_demuxer  = regexBetween(infoVideoDVD,"ID_DEMUXER=(\\S+)");
    this->id_filename = regexBetween(infoVideoDVD,"ID_FILENAME=(\\S+)");
    id_video_format = regexBetween(infoVideoDVD,"ID_VIDEO_FORMAT=(\\S+)");
    id_video_bitrate = regexBetween(infoVideoDVD,"ID_VIDEO_FORMAT=(\\S+)").toDouble(b);
    id_video_width = regexBetween(infoVideoDVD,"ID_VIDEO_WIDTH=(\\S+)").toDouble(b);
    id_video_height = regexBetween(infoVideoDVD,"ID_VIDEO_HEIGHT=(\\S+)").toDouble(b);
    id_video_fps = regexBetween(infoVideoDVD,"ID_VIDEO_FPS=(\\S+)").toDouble(b);
    id_video_aspect = regexBetween(infoVideoDVD,"ID_VIDEO_ASPECT=(\\S+)").toDouble(b);
    id_audio_format = regexBetween(infoVideoDVD,"ID_AUDIO_FORMAT=(\\S+)").toDouble(b);
    id_audio_bitrate = regexBetween(infoVideoDVD,"ID_AUDIO_BITRATE=(\\S+)").toDouble(b);
    id_audio_rate = regexBetween(infoVideoDVD,"ID_AUDIO_RATE=(\\S+)").toInt(b);
    id_audio_nch = regexBetween(infoVideoDVD,"ID_AUDIO_NCH=(\\S+)").toInt(b);
    id_length = regexBetween(infoVideoDVD,"ID_LENGTH=(\\S+)").toDouble(b);
    id_seekable = regexBetween(infoVideoDVD,"ID_SEEKABLE=(\\S+)").toDouble(b);

    number_of_chapters = regexBetween(infoVideoDVD,"There are ([0-9]+) chapters in this DVD title").toInt(b);
    number_of_audio = regexBetween(infoVideoDVD,"number of audio channels on disk: ([0-9]+)").toInt(b);
    number_of_subtitle  = regexBetween(infoVideoDVD,"number of subtitles on disk: ([0-9]+)").toInt(b);

    // Subtitles
    for(int sid=1;sid<=number_of_subtitle;sid++){
        c_subtitle sub(DVDWorkingDirectory,title_number,sid,infoVideoDVD);
        this->list_subtitle.append(sub);
    }

    // Audio
    QStringList strList = infoVideoDVD.split(QRegExp("\n"));
    //qDebug("______________________ %d _______________________________",strList.size());
    QSet<int> listOfAid;

    foreach(QString s, strList)
    {
        QRegExp r("ID_AUDIO_ID=(\\S+)");
        bool *b = new bool;
        if (s.contains(r))
        {
            int l_aid = r.cap(1).toInt(b);
            listOfAid.insert(l_aid);
        }
    }


    foreach(int l_aid, listOfAid)
    {
        QString s = QString("aid: %1").arg(l_aid);
        foreach(QString s2, strList)
        {
            c_audio c;
            if (regexBetween(s2,"ID_AUDIO_CODEC=(\\S+)") != "")
                c.id_audio_codec = regexBetween(s2,"ID_AUDIO_CODEC=(\\S+)");
            if (regexBetween(s2,"ID_VIDEO_CODEC=(\\S+)") != "")
                c.id_video_codec = regexBetween(s2,"ID_VIDEO_CODEC=(\\S+)");
            if (s2.contains(s))
            {
                //qDebug("------- %s",s2.toLatin1().data());
                // s2 = audio stream: 2 format: dts (5.1) language: en aid: 138.
                // s2 = audio stream: 0 format: lpcm (stereo) language: en aid: 160.
                QRegExp reg("audio stream: (\\S+) format: (\\S+) \\((\\S+)\\) language: (\\S+) aid: (\\S+)");

                if (s2.contains(reg))
                {
                    c.streamNumber = reg.cap(1).toInt(b);
                    c.format = reg.cap(2);
                    c.format2 = reg.cap(3);
                    c.lang = reg.cap(4);
                    QString s_aid = reg.cap(5);s_aid.replace(".","");
                    c.aid = s_aid.toInt(b);
                    c.title_number = title_number;
                    c.DVDWorkingDirectory = this->DVDWorkingDirectory;
                    c.enabled = true;
                    // video-title-1-aid-129-lang-en.ac3
                    c.audio_file_name = DVDWorkingDirectory + QString("/%1/video-title-%2-aid-%3-lang-%4.%5")
                                        .arg(title_number).arg(title_number).arg(c.aid).arg(c.lang).arg(c.format);


                    this->appendToListAudio(c);
                }
            }
        }
    }

    //Chapter
    QString l_chap = regexBetween(infoVideoDVD,"CHAPTERS: (\\S+)");
    l_chap.replace(QRegExp(",$"),"");
    qDebug("Chapters of title %d = %s",this->title_number, l_chap.toLatin1().data());
    QStringList list_str_chap = l_chap.split(",");
    int compteur = 0;
    foreach(QString c,list_str_chap)
    {
        compteur++;
        if (c != "" || ! c.contains(QRegExp("[a-z]+")))
        {
            c_chapter chapter;
            chapter.title_number = this->title_number;
            chapter.beginQString = c;
            chapter.beginQTime = QTime::fromString(c,"h:m:s");
            chapter.number = compteur;
            chapter.enabled = true;
            chapter.chapter_name = QString("Chapter %1").arg(compteur);
            this->appendToListChapter(chapter);
        }
    }

    if (this->list_chapter.size() != this->number_of_chapters)
    {
        QString errorMsg =
                QString("Error in chapter count %1 != %2 for title %3").arg(this->list_chapter.size()).arg(this->number_of_chapters).arg(this->title_number);
        this->number_of_chapters = this->list_chapter.size();
        qDebug("%s", errorMsg.toLatin1().data());
        //QMessageBox::information( 0, "Kakola :-)",errorMsg);
    }
    if (this->list_audio.size() != this->number_of_audio)
    {
        QString errorMsg =
                QString("Error in audio count %1 != %2 for title %3").arg(this->list_audio.size()).arg(this->number_of_audio).arg(this->title_number);
        QMessageBox::information( 0, "Kakola :-)",errorMsg);
    }
    if (this->list_subtitle.size() != this->number_of_subtitle)
    {
        QString errorMsg =
                QString("Error in audio count %1 != %2 for title %3").arg(this->list_subtitle.size()).arg(this->number_of_subtitle).arg(this->title_number);
        QMessageBox::information( 0, "Kakola :-)",errorMsg);
    }
}

c_chapter::c_chapter()
{

}



bool c_title::appendToListChapter(c_chapter c)
{
    bool exist = false;
    foreach(c_chapter a, this->list_chapter)
    {
        if (a.number == c.number && a.title_number == c.title_number)
        {
            exist = true;
            break;
        }
    }

    if (exist == false)
    {
        this->list_chapter.append(c);
        return true;
    }

    return false;
}

bool c_title::appendToListAudio(c_audio c)
{
    bool exist = false;
    foreach(c_audio a, this->list_audio)
    {
        if (a.aid == c.aid)
        {
            exist = true;
            break;
        }
    }

    if (exist == false)
    {
        this->list_audio.append(c);
        return true;
    }

    return false;
}

bool c_title::appendToListSubtitle(c_subtitle s)
{
    bool exist = false;
    foreach(c_subtitle a, this->list_subtitle)
    {
        if (a.sid == s.sid)
        {
            exist = true;
            break;
        }
    }

    if (exist == false)
    {
        this->list_subtitle.append(s);
        return true;
    }

    return false;
}

void CRipDVD::fill_list_title()
{
    for(int i=1; i<=this->numberOfTitleInDVD;i++)
    {
        c_title c(DVDWorkingDirectory,i,this->allInfoDVD[i]);
        this->list_title.append(c);
        this->fill_tree_widget(c);
    }
    return ;
}

void CRipDVD::fill_tree_widget(c_title c)
{
    int i = 0;

    if (c.title_number == 1)
        ui->treeWidget->clear();

    QTreeWidgetItem *item_vob = new QTreeWidgetItem(ui->treeWidget);
    item_vob->setCheckState(i,Qt::Checked);
    item_vob->setText(i,c.vob_file);
    item_vob->setText(i+1,"Title");
    item_vob->setExpanded(true);

    QTreeWidgetItem *parent_audio    = new QTreeWidgetItem(item_vob);
    parent_audio->setCheckState(0,Qt::Checked);
    parent_audio->setText(i,"Audio");
    parent_audio->setExpanded(false);
    foreach(c_audio a,c.list_audio)
    {
        QTreeWidgetItem *item_audio    = new QTreeWidgetItem(parent_audio);
        item_audio->setCheckState(i,Qt::Checked);
        item_audio->setText(i,a.audio_file_name);
        item_audio->setText(i+1,"Audio");
    }

    QTreeWidgetItem *parent_subtitle    = new QTreeWidgetItem(item_vob);
    parent_subtitle->setCheckState(0,Qt::Checked);
    parent_subtitle->setText(i,"subtitle");
    parent_subtitle->setExpanded(false);
    foreach(c_subtitle s,c.list_subtitle)
    {
        QTreeWidgetItem *item_subtitle    = new QTreeWidgetItem(parent_subtitle);
        item_subtitle->setCheckState(i,Qt::Checked);
        item_subtitle->setText(i,s.sub_file_name);
        item_subtitle->setText(i+1,"subtitle");
    }

    QTreeWidgetItem *parent_chapter    = new QTreeWidgetItem(item_vob);
    parent_chapter->setCheckState(0,Qt::Checked);
    parent_chapter->setText(i,"Chapter");
    parent_chapter->setExpanded(false);
    foreach(c_chapter s,c.list_chapter)
    {
        QTreeWidgetItem *item_chapter    = new QTreeWidgetItem(parent_chapter);
        item_chapter->setCheckState(i,Qt::Checked);
        item_chapter->setText(i,QString("%1 %2").arg(s.number).arg(s.beginQString));
        item_chapter->setText(i+1,"Chapter");
    }
    return ;
}


QString regexBetween(QString str,QString sreg,int log)
{
    QString res;
    QRegExp reg(sreg);
    if ( str.contains(reg) )
        res = reg.cap(1);
    else
        res = "";

    if (res.size() > 400)
        qDebug("Mamamamamama bug %s",res.toLatin1().data());

    if (log != 0)
        qDebug("Variable DVD %s = %s",sreg.toLatin1().data(),res.toLatin1().data());
    return res;
}

void CRipDVD::on_startDVDButton_clicked()
{
    qDebug("Starting DVD Rip");

}
